import { RouteRecord } from './constants';
import { HandlerCallback } from '../common/service/handlerService';
import {getLogger} from 'pinus-logger';
import * as path from 'path';
let logger = getLogger('pinus', path.basename(__filename));

export interface IMsgPreprocessor {
    preprocessReq: (routeRecord: RouteRecord, msg: any) => any;
    preprocessRes: (routeRecord: RouteRecord, msg: any) => any;
    preprocessPush: (route: string, msg: any) => any;
}

export class MsgUtil {
    private static preprocessor: IMsgPreprocessor;

    public static get Preprocessor() {
        return MsgUtil.preprocessor;
    }
    public static set Preprocessor(preprocessor: IMsgPreprocessor) {
        MsgUtil.preprocessor = preprocessor;
    }

    public static preprocessReq(routeRecord: RouteRecord, msg: any) {
        if (!MsgUtil.preprocessor) {
            return msg;
        }
        return MsgUtil.preprocessor.preprocessReq(routeRecord, msg);
    }
    
    public static preprocessRes(routeRecord: RouteRecord, msg: any) {
        if (!MsgUtil.preprocessor) {
            return msg;
        }
        return MsgUtil.preprocessor.preprocessRes(routeRecord, msg);
    }

    public static preprocessPush(route: string, msg: any) {
        if (!MsgUtil.preprocessor) {
            return msg;
        }
        return MsgUtil.preprocessor.preprocessPush(route, msg);
    }

}
